package com.nervous.jiaoli.user.user;


import com.nervous.jiaoli.common.Result;
import com.nervous.jiaoli.user.user.User;
import com.nervous.jiaoli.user.user.UserDto;
import com.nervous.jiaoli.user.user.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/*
    在springboot应用中的几个概念
    1、根包：springboot启动类所在的包
    2、spring容器管理的组件（bean）都应该定义在根包下，或者根包的子包下
 */

@Slf4j
@RestController //说明这是一个受spring容器管理的控制器组件(bean)
@RequestMapping("/user")
public class UserAPI {


    //引入依赖对象
    @Resource //此注解表示从容器中引入依赖对象
    private UserService userService;

    @RequestMapping("/user-list")
    public Result userList() {
        return Result.success("查询用户成功！",userService.getUserList());
    }

    //返回一个json串
    @RequestMapping("/user-query")
    public Result userList(@RequestBody UserDto userDto) { //dto会根据属性与参数名匹配的规则自动接收
        return Result.success("查询用户成功！",userService.getUserList(userDto));
    }

    @RequestMapping("/user-add")
    public Result addUser(@RequestBody UserDto userDto){
        userService.addUser(userDto);
        return Result.success("添加用户信息成功");
    }

    @RequestMapping("/user-delete")
    public  Result delUser(@RequestBody UserDto userDto){
        userService.delUser(userDto);
        return Result.success("删除用户信息成功");
    }
    @RequestMapping("/user-update")
    public Result updateUser(@RequestBody UserDto userDto){
        userService.updateUser(userDto);
        return Result.success("更新用户信息成功");
    }
    @RequestMapping("/user-count")
    public Result countUser(){
        return Result.success("生成报表成功",userService.countUser());
    }
}
